<template>
	<view>
		<swiper autoplay circular indicator-dots class="swiper" v-if="banner">
			<swiper-item v-for="i in banner">
				<image mode="aspectFill" :src="i"></image>
			</swiper-item>
		</swiper>
		<block v-for="i in list">
			<tggoods :goods="i" :state="state"></tggoods>
		</block>
		<view class="hasmore">{{hasmore?'加载中':'没有更多了'}}</view>
	</view>
</template>

<script>
	import tggoods from './components/tggoods'
	export default {
		components: {
			tggoods
		},
		data() {
			return {
				page:1,
				limit:10,
				hasmore:true,
				list:[],
				banner:''
			}
		},
		onLoad(op){
			//type  1体验区 2推广区 3新会员专享
			this.type = op.type
			this.mch_id = op.p_mch_id
			this.getList()
			this.getBanner()
		},
		onReachBottom(){
			if(this.hasmore){
				this.getList()
			}
		},
		methods: {
			getBanner() {
				this.$request({
					url: this.$api.jimai.index_part,
					data: {
						mch_id: this.mch_id
					}
				}).then(info => {
					
					if(this.mch_id == '0'){
						this.banner = info.data.setting.platform[`banner${this.type}`]
						this.state = info.data.setting.platform.state
					}else{
						this.banner = info.data.setting.mch[`banner${this.type}`]
						this.state = info.data.setting.mch.state
					}
				}).catch(info => {})
			},
			getList() {
				this.$showLoading();
				this.$request({
				    url: this.$api.jimai.goodsList,
				    data: {
				        type: this.type,
						mch_id:this.mch_id,
						page:this.page,
						limit:this.limit
				    }
				}).then(info => {
					this.page ++
				    this.$hideLoading();
				    if (info.code === 0) {
						if(info.data.list){
							this.list = this.list.concat(info.data.list)
							this.hasmore = info.data.list.length == this.limit
						}else{
							this.hasmore = false
						}
				       
				    }
				}).catch(info => {
				    this.$hideLoading();
				})
			},
			totiyan(type) {
				uni.navigateTo({
					url: '/plugins/jimai/tyList?type=' + type
				})
			}
		},
	}
</script>

<style scoped>
	.swiper {
		width: 100%;
		height: 300upx;
	}

	.swiper image {
		width: 100%;
		height: 100%;
	}

	page {
		background: #f7f7f7;
	}
</style>
